package com.aide.simplification.global.taglib;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.ecs.html.Script;

public class MessageAlert extends TagSupport {

	private static final long serialVersionUID = 5488127664321985313L;
	private String attrid = "msg";
	private String testval = "";
	private String msg = "";
	private boolean test = false;

	public int doEndTag() throws JspException {
		ServletRequest request = pageContext.getRequest();
		JspWriter out = pageContext.getOut();
		if (!test&&!testval.equals("")) {
			if (request.getAttribute(attrid).equals(testval)) {
				test = true;
			}
		}
		if (request.getAttribute(attrid) != null) {
			test = true;
			msg=request.getAttribute(attrid).toString();
			request.removeAttribute(attrid);
		}
		if (test&&!msg.equals("")) {
			Script script = new Script();
			script.setType("text/javascript");
			script.setTagText("alert('" + msg + "')");
			try {
				out.println(script.toString());
			} catch (IOException e) {
			}
		}
		return EVAL_PAGE;
	}

	public String getAttrid() {
		return attrid;
	}

	public void setAttrid(String attrid) {
		this.attrid = attrid;
	}

	public String getTestval() {
		return testval;
	}

	public void setTestval(String testval) {
		this.testval = testval;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public boolean isTest() {
		return test;
	}

	public void setTest(boolean test) {
		this.test = test;
	}
}
